//
// Created by weslywang on 2020/5/9.
//

#include "../common/common.h"

bool isAlphaNumeric(char ch) {
    if (ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9') {
        return true;
    }
    return false;
}

bool isPalindrome(string s) {
    bool re = true;
    for (int i = 0, k = s.length() - 1; i < k;) {
        char ch1 = s[i], ch2 = s[k];
        if (ch1 >= 'A' && ch1 <= 'Z') {
            ch1 = 'a' + ch1 - 'A';//转成小写
        }
        if (ch2 >= 'A' && ch2 <= 'Z') {
            ch2 = 'a' + ch2 - 'A';//转成小写
        }
        if (!isAlphaNumeric(ch1)) {
            i++;
            continue;
        }
        if (!isAlphaNumeric(ch2)) {
            k--;
            continue;
        }
        if (ch1 != ch2) {
            re = false;
            break;
        }else{
            i++;
            k--;
        }
    }
    return re;
}

int main() {
    Common common;
    int a[] = {1, 2, 3, 4, 5};
    vector<vector<int>> numList = common.loadData();
    for (int i = 0; i < numList.size(); i++) {
        cout << isPalindrome("race a car") << endl;
        cout << "**************" << endl;
    }
    return 0;
}